/*
 * Motor.cpp
 *
 *  Created on: Apr 12, 2010
 *      Author: andrew
 */

#include "Motor.h"
#include <cmath>

Motor::Motor(double Voltage, double proportionality, double current, double resistance, int n) {
	V0 = Voltage;
	V = Voltage;
	Kv = proportionality;
	I0 = current;
	R = resistance;
	Kt = 1352/Kv;
	N = n;
}

void Motor::setThrottle(double throttle){
	V = V0*throttle;
}

int Motor::getNumberOfMotors(){
	return N;
}

double Motor::getMaxRPM(){
	return Kv*(V - I0*R);
}

double Motor::getPowerIn(double RPM){
	double I = (V - RPM/Kv)/R;
	return V*I;
}

double Motor::getPowerOut(double RPM){
	double QinNm = getTorque(RPM);
	return QinNm*RPM*2.0*M_PI/60.0;
}

double Motor::getEfficiency(double RPM){
	return getPowerOut(RPM)/getPowerIn(RPM);
}

double Motor::getTorque(double RPM){
	double I = (V - RPM/Kv)/R;
	double Q = Kt*(I-I0);
	return Q*0.00706;
}
